<template>
	<view>
		<u-gap height="96" bg-color="white"></u-gap>
		<view style="padding-left: 30rpx; padding-right: 30rpx;">
			<form @submit="loginSubmit" @reset="loginReset" >
				<view style="font-size: 72rpx; font-weight: 900;">进入</view>
				<u-gap height="16" bg-color="white"></u-gap>
				<view style="font-weight: 300;">氢葱圈 - 在线动态互动社交</view>
				<u-gap height="16" bg-color="white"></u-gap>
				<input placeholder="请输入用户名" v-model="username" maxlength="20" confirm-type="next" class="login_input"/>
				<input placeholder="请输入密码" v-model="password" password="true" maxlength="24" confirm-type="done" class="login_input"/>
				
				<view style="font-size:21rpx">
					<u-checkbox
						active-color="#FCAB01"
						class="checkbox"
						v-model="limit" 
						:name="limited"
					></u-checkbox>
					是否同意<text style="color:#FCAB01">《不断同学账户使用准则》</text>及<text style="color:#FCAB01">《隐私条款》</text>
				</view>
				<u-button type="defult"  form-type="submit" :hair-line="false"  class="u-m-t-30" style="background-color:#FCAB01;color: #fff;border-radius: 8px;" >进入氢葱圈</u-button>
			</form>
			<u-gap height="32" bg-color="white"></u-gap>
			<view style="float: right;display: inline;">
				<text style="color: #FCAB01;" @click="reg">注册账户</text>
			</view>
			<view style="float: left ;display: inline;">
				<text style="color: #FCAB01;">忘记密码</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username:'',
				password:'',
				limit:false
			}
		},
		onLoad() {
			
		},
		methods: {
			reg(Info){
				uni.navigateTo({
					url:"reg"
				})
			},
			loginSubmit(LogInfo){
				
				uni.request({
					url:'http://api.cc.ibuduan.com/test/login.php',
					method:'GET',
					data:{
						un:this.username,
						pwd:this.password
					},
					success:(res) => {
						if(res.data.err_code == '0'){
							
							try {
							    uni.setStorageSync('bcc_token', res.data.text.token);
								uni.reLaunch({
								    url: '../index/index'
								});
							} catch (e) {
							    uni.showToast({
							    	icon:0,
									title:'token写入失败'
							    })
							}
						}else if(res.data.err_code == 'CK02001'){
							uni.showModal({
								title:'登录失败',
								content:'用户名或密码错误 Code:CK02001'
							})
						}else if(res.data.err_code == 'CK02002'){
							uni.showModal({
								title:'登录失败',
								content:'无此用户 Code:CK02002'
							})
						}else{
							uni.showModal({
								title:'登录失败',
								content:'其他错误 Code:CK00000',
							})
						}
					},
					fail:uni.showModal({
						title:'请求失败',
						content:'网络错误或服务器处于维护状态 \n（作者服务器可能又挂了）'
					})
				})
			}
		}
	}
</script>

<style>
.login_input{
	margin-top: 30rpx;
	margin-buttom: 30rpx;
	background-color: #f6f6f6;
	height: 96rpx;
	padding-left: 8px;
	border-radius: 8px;
	
}
.checkbox{
	padding-top: 24rpx;
	color: #FCAB01;
	transform:scale(0.9)
}
</style>
